package com.cx.stream;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;
import java.util.stream.Stream;

/**
 * @author zhangshuai
 * @version V1.0
 * @Project Java2_26
 * @Package com.cx.stream
 * @Description:
 * @Date 2025/5/23 10:07
 */

public class StreamTest {
    public static void main(String[] args) throws IOException {
        //Stream流跟集合有点类似，但是集合是存储数据的，Stream流是计算数据的，保存一些操作，操作集
        List<Object> list = new ArrayList<>();
        list.add(1);
        list.add(21);
        list.add(31);
        list.add(4);
        Stream<Object> stream = list.stream();

        HashMap<Object, Object> map = new HashMap<>();


        //数组
        Integer[] integers = {1, 2, 31, 4, 51, 6, 71, 8, 9, 10};
        Stream<Integer> stream1 = Arrays.stream(integers);

        //Stream.of()
        Stream<Integer> stream2 = Stream.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
        System.out.println(stream);
        System.out.println(stream1);
        System.out.println(stream2);

        //文件方式去创建
        Stream<String> lines = Files.lines(Paths.get("file.txt"));
        System.out.println(lines);

    }
}